<?php 
/**
 * 建立Smarty桥梁。
 */
class SmartyView{
	private static $smarty = NULL;

	public function __construct(){
		if(!is_null(self::$smarty)) return;
		$smarty = new Smarty();
		//模板目录
		$smarty->template_dir = APP_TPL_PATH.'/'.CONTROLLER."/";
		//编译目录
		$smarty->compile_dir = APP_COMPILE_PATH;
		//缓存目录
		$smarty->cache_dir = APP_CACHE_PATH;
		//定界符
		$smarty->left_delimiter = C('LEFT_DELIMITER');
		$smarty->right_delimiter = C('RIGHT_DELIMITER');
		//是否开启缓存，默认不开启
		$smarty->caching = C('CACHING');
		//缓存时间
		$smarty->cache_lifetime = C('CACHE_TIME');

		self::$smarty = $smarty;
	}

	/**
	 * [display 调用模板]
	 * @param  [type] $tpl [路径]
	 * @return [type]      [description]
	 */
	protected function display($tpl){
		self::$smarty->display($tpl,$_SERVER['REQUEST_URI']);
	}

	/**
	 * [assign 模板赋值]
	 * @param  [type] $var   [key]
	 * @param  [type] $value [值]
	 * @return [type]        [description]
	 */
	protected function assign($var,$value){
		//调用samrty里面的方法
		self::$smarty->assign($var,$value);
	}

	/**
	 * 是否缓存
	 * [is_cache description]
	 * @param  [type]  $tpl [description]
	 * @return boolean      [description]
	 */
	protected function isCached($tpl = NULL){
		if(!C('SMARTY_ON')) halt('请先开启smarty');
		$tpl = $this->get_tpl($tpl);
		return self::$smarty->isCached($tpl,$_SERVER['REQUEST_URI']);
	}
}
?>